package ext.test;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import ext.tianma.doc.SendOut.service.ConfigService;
import ext.tianma.doc.SendOut.util.HttpUtils;
import ext.tianma.doc.SendOut.util.HttpUtils2;

public class test {

	//查询供应商sdf
	public static String test1() throws JSONException {
		//String url = "http://api-tmapi-sit.apps-dev.tianma.cn/tm/api/entrance?apiNo=C1002";
		String url = "http://10.100.8.234:22128/ERPService/http/ERPSupplierInfo";
		String obj1 = "{ "
	+" \"serviceInterfaceCode\": \"ESBERPH0004\", "
	+" \"fromSystemCode\": \"101SDP\", "
	+" \"fromInterfaceCode\": \"\", "
	+" \"toInterfaceCode\": \"ERPW0017\", "
	+" \"ouZone\": \"OU_TMSH\", "
	+" \"factoryName\": \"\", "
	+" \"uuid\": \"653ab555e56909e754f0b1c359283069\", "
	+" \"requestTime\": \"2020-05-19 08:48:00\", "
	+" \"userName\": \"\", "
	+" \"password\": \"\", "
	+" \"sign\": \"\", "
	+" \"dataType\": \"JSON\", "
	+" \"data\": { "
	+" 	\"batchNumber\": \"20200519001\", "
	+" 	\"sourceCode\": \"SDP\", "
	+" 	\"supplierCode\": \"301747\", "
	+" 	\"supplierName\": \"\" "
	+" } "
	+" }";
		
//		JSONObject obj1 = new JSONObject();
//		JSONObject dataObj = new JSONObject();
//		dataObj.put("batchNumber", "20200519001");
//		dataObj.put("sourceCode", "SDP");
//		dataObj.put("supplierCode", "41");
//		dataObj.put("supplierName", "");
//		
//		obj1.put("serviceInterfaceCode", "ESBERPH0004");
//		obj1.put("fromSystemCode", "101SDP");
//		obj1.put("fromInterfaceCode", "");
//		obj1.put("toInterfaceCode", "ERPW0017");
//		obj1.put("ouZone", "OU_TMSH");
//		obj1.put("factoryName", "");
//		obj1.put("uuid", "653ab555e56909e754f0b1c359283069");
//		obj1.put("requestTime", "2020-05-18 08:48:00");
//		obj1.put("userName", "");
//		obj1.put("password", "");
//		obj1.put("sign", "");
//		obj1.put("dataType", "JSON");
//		obj1.put("data", dataObj);
		
		String s = HttpUtils.post(url,obj1.toString(),0,null);
		System.out.println(s);
		return s;
	}
	
	//接口平台获取供应商接口人
	private static void test2() {
		String url = "http://api-tmapi-sit.apps-dev.tianma.cn/tm/api/entrance?apiNo=F2002";
		String  data = "{" + 
				"  \"page\": {" + 
				"    \"numberOfPages\": 0," + 
				"    \"pageNumber\": 1," + 
				"    \"pageSize\": 5," + 
				"    \"totalItemCount\": 0" + 
				"  }," + 
				"  \"search\": {" + 
				"    " + 
				"    \"orgName\": \"失效-上海杜哲贸易有限公司\"" + 
				"   " + 
				"  }" + 
				"}";
		String s = HttpUtils.post(url,data,0,null);
		System.out.println(s);
	}
	
	public static void main(String[] args) {
		//供应商接口
//		try {
//			test1();
//		} catch (JSONException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		String ss = HttpUtils.get("http://139.224.111.22:8080/group1/upload?md5=12ce8c47524bc26b7314ff4392448172&output=json");
		System.out.println(ss);
		
		//接口人
//		test3();
		
//		try {
//			test4();
//		} catch (JSONException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		//文件传输
//		test5();
	}
	
	/**
	 * SOA获取接口人
	 */
	public static void test3() {
		String url = "http://10.100.8.234:22124/send/sde/datainfo";
		
//		String  data = "{" + 
//				"	\"serviceInterfaceCode\": \"ESBSDEH0002\"," + 
//				"	\"fromSystemCode\": \"101SDP\"," + 
//				"	\"fromInterfaceCode\": \"\"," + 
//				"	\"toInterfaceCode\": \"SDPH0017\"," + 
//				"	\"ouZone\": \"OU_TMSH\"," + 
//				"	\"factoryName\": \"\"," + 
//				"	\"uuid\": \"653ab555e56909e754f0b1c359283069\"," + 
//				"	\"requestTime\":\"2020-05-20 08:48:00\", "
//				+ "	\"userName\":\"\", "
//				+ "	\"password\":\"\", "
//				+ "	\"sign\":\"\", "
//				+ "	\"dataType\":\"JSON\", " +
//				"	\"data\": {" + 
//				"		\"page\": {" + 
//				"			\"pageNumber\": 1," + 
//				"			\"pageSize\": 10" + 
//				"		}," + 
//				"		\"search\": {" + 
////				"			\"email\":\"\" ," + 
////				"			\"fullName\":\"\" ," + 
////				"			\"orgCode\":\"\" ," + 
//				"			\"orgName\":\"失效-上海杜哲贸易有限公司\" " + 
////				"			,\"userNo\":\"\" ," + 
////				"			\"userType\":\"\" " + 
//				"		}" + 
//				"	}" + 
//				"}";
		
		JSONObject obj = new JSONObject();
		
		try {
			JSONObject page = new JSONObject();
			page.put("pageNumber", 1);
			page.put("pageSize", 20);
			
			JSONObject search = new JSONObject();
			//search.put("orgCode", "41");//根据供应商编码查询
			search.put("orgName", "test2016");//根据供应商名称查询
			
			JSONObject data = new JSONObject();
			data.put("page", page);
			data.put("search", search);
			
			obj.put("serviceInterfaceCode", "ESBSDEH0002");//ESBSDE0001  ESBSDEH0002
			obj.put("fromSystemCode", "101SDP");
			obj.put("fromInterfaceCode", "");
			obj.put("toInterfaceCode", "SDPH0017");
			obj.put("ouZone", "OU_TMSH");
			obj.put("factoryName", "");
			obj.put("uuid", "653ab555e56909e754f0b1c359283069");
			obj.put("requestTime", "2020-05-20 08:48:00");
			obj.put("userName", "");
			obj.put("password", "");
			obj.put("sign", "");
			obj.put("dataType", "JSON");
			obj.put("data", data.toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		
		String s = HttpUtils.post(url,obj.toString(),0,null);
		System.out.println(s);
	}
	
	
/**
 * 文件上传
 * @throws JSONException
 */
public static void test4() throws JSONException {
		
//		List<String> receiveUserIdList = new ArrayList<String>();
//		JSONArray receiveUserIdList = new JSONArray();
//		receiveUserIdList.put("38e1e2c8-9008-11ea-a87e-005056b44a41");
//		
//		JSONArray fileAddressList = new JSONArray();
//		fileAddressList.put("/group1/default/20200522/10/44/4/___notices");
		
		
		List<String> receiveUserIdList = new ArrayList<String>();
		receiveUserIdList.add("38e1e2c8-9008-11ea-a87e-005056b44a41");
		
		List<String> fileAddressList = new ArrayList<String>();
		fileAddressList.add("/group1/default/20200522/10/44/4/___notices");
		
		
		JSONObject data = new JSONObject();
		data.put("name", "测试_name");
		data.put("materialCode", "测试_materialCode");
		data.put("information", "测试_information");
		data.put("productNum", "测试_productNum");
		data.put("purpose", "测试_purpose");
		data.put("size", "100");
		data.put("roleFlag", "in");
		data.put("receiveUserIdList", receiveUserIdList);
		data.put("fileAddressList", fileAddressList);
		data.put("userNo", "B189466");
		
		JSONObject params = new JSONObject();
		params.put("serviceInterfaceCode", "ESBSDEH0001");
		params.put("fromSystemCode", "101SDP");
		params.put("fromInterfaceCode", "");
		params.put("toInterfaceCode", "SDPH0016");
		params.put("ouZone", "OU_TMSH");
		params.put("factoryName", "");
		params.put("uuid", "653ab555e56909e754f0b1c359283069");
		params.put("requestTime", "2020-05-11 09:55:42");
		params.put("userName", "");
		params.put("password", "");
		params.put("sign", "");
		params.put("dataType", "JSON");
		params.put("data", data.toString());
		
		String url = "http://10.100.8.234:22124/send/sde/datainfo";
		String s = HttpUtils.post(url,params.toString(),0,null);
		System.out.println(s);
		
	}


	public static void test5() {
		String docUrl = "http://139.224.111.22:8080/group1/big/upload/b8f30a8702bedb415634778519db498e";
		System.out.println("开始");
		String second_url ="http://139.224.111.22:8080/group1/upload/";//秒传
		String fileId = docUrl.substring(docUrl.lastIndexOf("/") + 1);
//		String url = StrUtil.format("{}?md5={}&output=json", second_url, fileId);
		String md5_url = second_url + "?md5="+fileId+"&output=json";
		String ss = HttpUtils2.getRequest(md5_url);
		
		System.out.println(ss);
	}
}
